#include <string>
#include <sstream>
#include <string.h>
#include <stdio.h>

#include "common/HiCommonLog.hpp"

using namespace std;

string Byte2Hex(const uint8_t* bArray, size_t bArray_len) {
   stringstream oss;
    oss<<std::uppercase;
	for(size_t i = 0; i< bArray_len; i++)	{
        if (i % 2 == 0 && i != 0 && i% 8 != 0) {
            //oss<<" ";
        }

        if (i != 0 && i% 64 == 0) {
            //oss<<"\n";
        }
        
        oss.width(2);
        oss.fill('0');
        oss<<std::hex<< (int)(*(bArray + i));
	}
    //oss<<std::endl;
    return oss.str();
}

size_t hexCharToByte(uint8_t* data, size_t len, const char* line) {
	size_t lineLen = strlen(line);
	size_t index = 0;
	char hex[3] = {0};
	uint8_t val = 0;
	for (size_t i = 0; i < lineLen; i += 2) {
		memcpy(hex, line + i, 2);
		hex[2] = '\0';
		sscanf(hex, "%x", &val);
		*(data+i/2) = val;
		index++;
	}
	return lineLen / 2;
}